import com.ynny.h13.Entity.Clazz;
import com.ynny.h13.Mapper.ClazzMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class homework13 {
    @Test
    public void test1() throws IOException {
        SqlSession sqlSession = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml")).openSession(true);
//        根据学号更新学生的一个或多个信息
//        将学号为20190001的学生的姓名改为‘测试’,性别改为‘女’，年龄改为23
//        StudentsMapper mapper = sqlSession.getMapper(StudentsMapper.class);
//        Students students = new Students();
//        students.setNumber("20190001");
//        students.setName("测试");
//        students.setGender("女");
//        students.setAge(23);
//        int i = mapper.updateByNumber(students);
//        if (i > 0){
//            System.out.println("更新成功"+i);
//        }else {
//            System.out.println("更新失败"+i);
//        }

//        根据学号、年级和班级中的0个、一个或多个条件删除学生信息
//        StudentsMapper mapper = sqlSession.getMapper(StudentsMapper.class);
//        Students students = new Students();
//        students.setNumber("20190002");
//        students.setGrade("高一");
//        students.setClazz("3班");
//        int i = mapper.deleteByNumber(students);
//        if (i > 0){
//            System.out.println("删除成功"+i);
//        }else {
//            System.out.println("删除失败"+i);
//        }

//        根据年级和班级查询班级信息,以及其一对多关系中的学生信息
        ClazzMapper mapper = sqlSession.getMapper(ClazzMapper.class);
        Clazz clazz = new Clazz();
        clazz.setGrade("高三");
//        clazz.setClazz("3班");
        List<Map> clazzByGradeAndClazz = mapper.selectClazzByGradeAndClazz(clazz);
        for (Map map : clazzByGradeAndClazz) {
            System.out.println(map);
        }

//        根据教师编号查询教师信息,以及其多对多关联的班级信息
//        TeacherMapper mapper = sqlSession.getMapper(TeacherMapper.class);
//        List<Map> teacherByNumber = mapper.selectTeachersByNumber("10003");
//        for (Map map : teacherByNumber) {
//            System.out.println(map);
//        }

    }
}
